package au.com.langdale.gwt.client.model;


/**
 * Base for all Integer properties.  Concrete properties must 
 * provide _get(),  _set(), getPrecision(), getScale(), and getName().
 * 
 * @author adv
 *
 */
public abstract class IntegerProperty extends Property {
	public IntegerProperty() {
		// serializable ctor
	}

	protected abstract Integer _get(Object model);
	protected abstract void _set(Object model, Integer value);
	protected abstract int getPrecision();
	protected abstract int getScale();
	
	public int getLength() {
		return getPrecision() + (getScale() > 0? 1: 0);
	}

	public String get(Object model) {
		Integer value = _get(model);
		if( value != null)
			return value.toString();
		else
			return "";
	}

	public boolean isSet(Object model) {
		Integer value = _get(model);
		return value != null && value.intValue() != 0;
	}

	public void set(Object model, String value) {
		_set(model, Integer.valueOf(value));
	}

	public void set(Object model, boolean value) {
		_set(model, new Integer(value?1:0));
	}
	public String getStyleName() {
		return "int-field";
	}

}
